package com.ctgu.admin.system.repository;

import com.ctgu.admin.system.domain.Article;
import com.ctgu.common.constant.StatusConst;
import com.ctgu.modules.system.domain.Dept;
import com.ctgu.modules.system.domain.User;
import com.ctgu.modules.system.repository.BaseRepository;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 文章的持久层
 */
public interface ArticleRepository extends BaseRepository<Article, Long>{
    /**
     * @param user 用户id
     * @return 该用户的所有文章列表
     */
    public List<Article> findArticleByCreateBy(User user);

//    @Select("SELECT COUNT(article_class) FROM sys_article WHERE create_by=#{userID} GROUP BY article_class")
//    public List<Integer> getArticleClassCntFromUserID(Long userID);

    public List<Article> findArticlesByArticleClass(Byte classId);

    @Query(value = "SELECT * FROM sys_article where update_date in (select max(update_date) from sys_article where status=6 or status=7 group by article_class) order by article_class", nativeQuery = true)
    public List<Article> getLatestArticles();
}